package tree;

import java.util.Stack;

public class OverTurn {

    public static void main(String[] args) {
        TreeNodec four = new TreeNodec(4, null, null);
        TreeNodec five = new TreeNodec(5, null, null);
        TreeNodec two = new TreeNodec(2, four, five);
        TreeNodec three = new TreeNodec(3, null, null);
        TreeNodec one = new TreeNodec(1, two, three);
        System.out.println("先序");
        precedence(one);
    }

    private static TreeNodec precedence(TreeNodec root) {
        Stack<TreeNodec> reStack = new Stack<>();
        reStack.push(root);
        while (!reStack.isEmpty()) {
            TreeNodec pop = reStack.pop();
            if(pop.right != null) reStack.push(pop.right);
            if(pop.left != null) reStack.push(pop.left);
            TreeNodec swap  = pop.left;
            pop.left = pop.right;
            pop.right = swap;
        }
        return root;
    }

    public Tree invertTree(Tree root) {
        return null;
    }
}
